/*
 *  Copyleft( c ), @ xiyou linux group.
 *  All rights reserved.
 *
 *  File name: xylgkgfs_create_file.c.
 *  Programmer's name: Harry Wei.
 *  Start time: 2010, 11, 4.
 *  Finish time: 2010, 11, 5.
 *
 *  Programm introduction: use xylgkgfs to create a file.
 */

#include <linux/module.h>
#include <linux/fs.h>

extern struct dentry 
*xylgkgfs_create_file(const char *name, mode_t mode, 
			struct dentry *parent, void *data, 
			const struct file_operations *fops);

static int 
xylgkgfs_u8_set(void *data, u64 val)
{
	*(u8 *)data = val;
	return 0;
}
	
static int 
xylgkgfs_u8_get(void *data, u64 *val)
{
	*val = *(u8 *)data;
	return 0;
}

DEFINE_SIMPLE_ATTRIBUTE( fops_u8, xylgkgfs_u8_get, 
			xylgkgfs_u8_set, "%llu\n" );
DEFINE_SIMPLE_ATTRIBUTE( fops_u8_ro, xylgkgfs_u8_get, 
			NULL, "%llu\n" );

struct dentry 
*xylgkgfs_create_u8(const char *name, mode_t mode, 
			struct dentry *parent, u8 *value)
{
	if (!(mode & S_IWUGO))
		return( xylgkgfs_create_file(name, mode, 
				parent, value, &fops_u8_ro));
	return(xylgkgfs_create_file(name, mode, parent, 
				value, &fops_u8));
}

static u8 xylgkgfs_test;

static int 
__init init_create_file(void)
{
	xylgkgfs_create_u8("xylkgkfs_test", 0777, NULL, &xylgkgfs_test);
	return 0;
}

static void 
__exit exit_create_file(void)
{
	return;
}

module_init(init_create_file);
module_exit(exit_create_file);
MODULE_LICENSE( "GPL" );
